<meta title="Url Scheme配置" args="data"/>
<style>

</style>
<form class="form-horizontal" id="form" s="form,valid">
    <table class="table table-bordered table-condensed table-striped">
        <thead>
        <tr>
            <th>APP</th>
            <th>页面</th>
            <th>Url Scheme
                <span class="text-warning">使用{placeholder}参数占位</span>
            </th>
            <th class="text-right">操作</th>
        </tr>
        </thead>
        <tbody s="nda,loop" id="mappingList" s-data="data.urlSchemeList">
        <tr s-loop-role="empty">
            <td colspan="4" class="alert alert-warning">暂无数据</td>
        </tr>
        <tr s="row,datac" s-loop-role="row">
            <td>
                <select class="form-control ecomPlat input-sm" s="select"
                        name="ecomPlat"
                        s-build="S.get('/api/enum/valuesMap/core.enums.EcomPlat')">
                </select>
            </td>
            <td>
                <select class="form-control input-sm page"
                        name="page">
                    <option value="SEARCH">搜索</option>
                    <option value="ITEM_DETAIL">商品详情</option>
                </select>
            </td>
            <td>
                <textarea name="url" class="form-control url" s-valid-error="require()"></textarea>
            </td>
            <td class="text-right">
                <input autocomplete="off" type="button" s-click="del(this)" class="btn btn-sm btn-danger btn-outline" value="删除" />
            </td>
        </tr>
        </tbody>
        <tfoot>
        <tr class="form-inline">
            <td colspan="4">
                <input autocomplete="off" type="button" class="btn btn-sm btn-default" s-click="addNew()" value="新增" />
            </td>
        </tr>
        </tfoot>
    </table>
</form>
<script type="text/javascript">
    S.getContent = function () {
        var deferred = $.Deferred();
        $form.validate().done(function() {
            var obj = {
                urlSchemeList: []
            }
            var ecomPlatNodes = $form.node.find(".ecomPlat");
            var pageNodes = $form.node.find(".page");
            var urlNodes = $form.node.find(".url");
            ecomPlatNodes.each(function(i) {
                obj.urlSchemeList.push({
                    ecomPlat: $(this).val(),
                    page: pageNodes.get(i).value,
                    url: urlNodes.get(i).value
                })
            })
            deferred.resolve(obj)
        })
        return deferred;
    }
    function addNew() {
        $mappingList.addRow( {}, 'append')

    }
    function del($s) {
        $s.parent().node.remove();
    }
</script>